package com.nail.post.Listener;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.nail.post.utils.MailUtils;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import javax.mail.MessagingException;


public class ConsumerMessageLisener implements MessageListener{

    public void onMessage(Message message) {
        TextMessage textMessage = (TextMessage) message;
        System.out.println("_____---__-______-_____-----消息消费开始！1");
        try {
            System.out.printf("接收到的消息是："+textMessage.getText());
            JSONObject object = JSON.parseObject(textMessage.getText());
            //MailUtils.sendEmail(user.getEmail(),user.getCode());
            try {
                MailUtils.sendEmail(object.getString("email"),object.getString("code"));
            } catch (MessagingException e) {
                e.printStackTrace();
            }

        } catch (JMSException e) {
            e.printStackTrace();
        }
        System.out.println("+++++++===+++++++++++=消息消费结束！");
    }
}
